﻿/*
 * 
 * frmMerchandiseClass.cs
 * 
 * 查看商品类型
 * 
 * JF 2011-09-20
 * 
 * 
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace EShop.Client
{
    public partial class frmMerchandiseClass : frmBase
    {
        public frmMerchandiseClass()
        {
            InitializeComponent();
        }

        EShop.BLL.MerchandiseClassBLL oMerchandiseClassBLL = new EShop.BLL.MerchandiseClassBLL();
        EShop.Model.MerchandiseClass oMerchandiseClass = new EShop.Model.MerchandiseClass();

        private void frmMerchandiseClass_Load(object sender, EventArgs e)
        {
            GetAllMerchandiseClass();
        }

        private void GetAllMerchandiseClass()
        {
            //dgvMerchandiseClassList.DataSource = oMerchandiseClassBLL.QueryMerchandiseClass(null);
            //dgvMerchandiseClassList.Refresh();
            DataTable dt = oMerchandiseClassBLL.QueryMerchandiseClass(null);
            dgvMerchandiseClassList.Rows.Clear();
            int index = -1;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                index = dgvMerchandiseClassList.Rows.Add();
                dgvMerchandiseClassList.Rows[index].Cells["MerchandiseClassID"].Value = dt.Rows[i]["MerchandiseClassID"];
                dgvMerchandiseClassList.Rows[index].Cells["MerchandiseClassName"].Value = dt.Rows[i]["MerchandiseClassName"];
            }
        }

        private void dgvMerchandiseClassList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = e.RowIndex;
            ShowMerchandiseClass(index);
        }

        private void ShowMerchandiseClass(int index)
        {
            if (index == -1) return;
            string strMerchandiseClassID = string.Empty;
            try
            {
                strMerchandiseClassID = dgvMerchandiseClassList.Rows[index].Cells[0].Value.ToString();
            }
            catch
            { }
            if (string.IsNullOrEmpty(strMerchandiseClassID)) return;
            frmMerchandiseClassEdit fMerchandiseClassEdit = new frmMerchandiseClassEdit(strMerchandiseClassID);
            if (fMerchandiseClassEdit.ShowDialog() == DialogResult.OK)
            {
                GetAllMerchandiseClass();
            }
        }

        private void 查看商品类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int index = dgvMerchandiseClassList.SelectedRows[0].Index;
            ShowMerchandiseClass(index);
        }

        private void 新增商品类型ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmMerchandiseClassAppend merchandiseClassAppend = new frmMerchandiseClassAppend();
            merchandiseClassAppend.Owner = this;
            if (merchandiseClassAppend.ShowDialog() == DialogResult.OK)
            {
                GetAllMerchandiseClass();
            }
            merchandiseClassAppend.Dispose();
        }
    }
}
